#define DEBUG
#include <cstdio>
#define ADD(x, y) (x = (x+y)%mods)

using namespace std;

typedef long long ll;

const int maxn=200000, mods=998244353;

int main() {
  freopen("life.in", "r", stdin);
  freopen("life.out", "w", stdout);

  static int c[maxn+1];
  int n;
  scanf("%d", &n);
  for (int i=1; i<=n; i++) {
    scanf("%d", c+i);
  }

  static ll f[maxn+1][2][2][2], pow[maxn+1];
  f[0][0][0][0] = 1;
  pow[0] = 1;
  for (int i=0; i<n; i++) {
    pow[i+1] = pow[i]*2%mods;
    for (int j=0; j<2; j++) {
      for (int k=0; k<2; k++) {
        for (int l=0; l<2; l++) {
          if (c[i+1]!=1) {
            ADD(f[i+1][j][k][l], f[i][j][k][l]*(k ? pow[i-1] : 0)%mods);
            ADD(f[i+1][1][k][!l], f[i][j][k][l]*(k ? pow[i-1] : pow[i])%mods);
          }
          if (c[i+1]!=0) {
            ADD(f[i+1][j][k][l], f[i][j][k][l]*(j ? pow[i-1] : 0)%mods);
            ADD(f[i+1][j][1][!l], f[i][j][k][l]*(j ? pow[i-1] : pow[i])%mods);
          }
        }
      }
    }
  }

  ll sum=0;
  for (int i=0; i<2; i++) {
    for (int j=0; j<2; j++) {
      ADD(sum, f[n][i][j][1]);
    }
  }
  printf("%lld", sum);

  fclose(stdin);
  fclose(stdout);
  return 0;
}
